/// <reference path="GC.Spread.Sheets.d.ts" />
import * as React from 'react';
import { Spin } from 'antd';
import { listStore } from '../../stores/list';
import { observer } from 'mobx-react';
import { WeaPopoverHrm } from 'ecCom';
import { loadSpread, releaseSpread } from '../../util/loadSpread';
export interface IExcelProps {
    store: listStore;
}
export interface IExcelState {
    height: number;
}

@observer
export default class Excel extends React.Component<IExcelProps, IExcelState>{
    test: (str: string) => boolean | undefined;
    excelList:HTMLDivElement|null;
    render() {
        const { store } = this.props;
        const { windowTitle } = store;
        if(windowTitle != ''){
            document.title = windowTitle;
        }
        return (
            <div className="cube-excel-list"  ref={ref=>this.excelList = ref}>
                <WeaPopoverHrm />
                <Spin spinning={store.excelStore.loading} size="large">
                    <div className="cube-excel-list-host" ref={ref => store.host = ref}></div>
                </Spin>
            </div>
        )
    }
    componentDidMount() {      
        this.test = loadSpread(this.loadSparedjs);
    }

    componentWillUnmount() {
        releaseSpread(this.test);
    }
    
    loadSparedjs = () => {
        const { store } = this.props;
        if (store.host&& (window as any).GC) {
                store.excelStore.init(new GC.Spread.Sheets.Workbook(store.host, {}));
        }
    }
}